local thbattle__leimi_hongwu = fk.CreateSkill {

  name = "thbattle__leimi_hongwu$",

  tags = { Skill.Limited},

}



thbattle__leimi_hongwu:addEffect("active", {
  anim_type = "big",
  prompt = "#thbattle__leimi_hongwu",
  max_game_use_time = 1,
  min_target_num = 1,
  max_target_num = function()
    return #table.filter(Fk:currentRoom().alive_players, function(p)
      return p.role == "loyalist"
    end)
  end,
  target_filter =function (self, player, to_select, selected, selected_cards)
        return #selected < #table.filter(Fk:currentRoom().alive_players, function(p)
      return p.role == "loyalist"
    end) and player ~= to_select
  end,
  card_filter = Util.FalseFunc,
  can_use =function (self, player)
    return player.role == "lord" and player:usedSkillTimes(thbattle__leimi_hongwu.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    THB_Utility.addStatusMark(player, "@@thbattle__leimi_hongwu1")
    for _, to in ipairs(effect.tos) do
      local target = to
      THB_Utility.addStatusMark(target, "@@thbattle__leimi_hongwu1")
    end
    for _, p in ipairs(room.alive_players) do
      if p:getMark("@@thbattle__leimi_hongwu1") == 0 then
        room:addPlayerMark(p, "@@thbattle__leimi_hongwu2")
      end
    end
  end,
})

thbattle__leimi_hongwu:addEffect(fk.Damage, {
  global = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@thbattle__leimi_hongwu1") > 0 and data.card and
        data.card.trueName == "slash"
  end,
  on_cost=Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, thbattle__leimi_hongwu.name, "support")
    player.room:recover({
      who = player,
      num = data.damage,
      recoverBy = player,
      skillName = thbattle__leimi_hongwu.name,
    })
  end,
})

thbattle__leimi_hongwu:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card, to)
    return player:getMark("@@thbattle__leimi_hongwu1") > 0 and card.trueName == "slash"
  end,
})

thbattle__leimi_hongwu:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    return from:getMark("@@thbattle__leimi_hongwu2") > 0 and from:distanceTo(to) > 1 and card.trueName == "slash"
  end
})


thbattle__leimi_hongwu:addEffect(fk.TurnStart, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__leimi_hongwu.name) and player:hasSkill(thbattle__leimi_hongwu.name) and
        player:usedSkillTimes("thbattle__leimi_hongwu", Player.HistoryGame) == 1
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(player.room.alive_players) do
      if p:getMark("@@thbattle__leimi_hongwu1") > 0 then
        THB_Utility.removeStatusMark(p, "@@thbattle__leimi_hongwu1")
      elseif p:getMark("@@thbattle__leimi_hongwu2") > 0 then
        room:removePlayerMark(p, "@@thbattle__leimi_hongwu2")
      end
    end
  end,
})


return thbattle__leimi_hongwu